<?php

namespace app\common\model;

use app\common\model\trait\ConstValid;

class LotteryActivity extends base\LotteryActivity
{
    use ConstValid;

    protected $append = ["valid_text", "type_text"];

    // `type` tinyint(4) DEFAULT '1' COMMENT '抽奖类型，1个人抽，2运营方抽',
    const TYPE_PERSONAL = 1;
    const TYPE_OPERATE = 2;

    /**
     * 获取类型列表
     * @return array[]
     */
    public static function getTypeList(): array
    {
        return [
            ["value" => self::TYPE_PERSONAL, "name" => "个人抽"],
            ["value" => self::TYPE_OPERATE, "name" => "运营方抽"],
        ];
    }

    /**
     * 获取类型文本
     * @param $value
     * @param $data
     * @return string
     */
    public function getTypeTextAttr($value, $data): string
    {
        $text = "";
        $type = getValueFromArray("type", $data);
        $typeList = self::getTypeList();
        foreach ($typeList as $item) {
            if ($item["value"] == $type) {
                $text = $item["name"];
                break;
            }
        }
        return $text;
    }


}